package com.xingzuo.library_file.ui.fragment;

import android.view.View;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import com.alibaba.android.arouter.facade.annotation.Route;
import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.listener.OnItemClickListener;
import com.xingzuo.base.app.AppActivityKey;
import com.xingzuo.base.ui.mvp.base.ui.BaseMvpFragment;
import com.xingzuo.library_file.R;
import com.xingzuo.library_file.R2;
import com.xingzuo.library_file.adapter.FileAdapter;
import com.xingzuo.library_file.bean.FileBean;
import com.xingzuo.library_file.contract.FileContract;
import com.xingzuo.library_file.presenter.FilePresenter;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;
import butterknife.OnClick;

@Route(path = AppActivityKey.FILEFRAGMENT)
public class FileFragment extends BaseMvpFragment<FilePresenter> implements FileContract.View {
    @BindView(R2.id.rv_list)
    RecyclerView rvList;
    private FileAdapter adapter;
    private List<FileBean> fileBeans = new ArrayList<>();

    @Override
    public FilePresenter getPresenter() {
        return new FilePresenter();
    }

    @Override
    public int getViewId() {
        return R.layout.fragment_file;
    }

    @Override
    public void initView() {
        fileBeans.add(new FileBean());
        fileBeans.add(new FileBean());
        fileBeans.add(new FileBean());
        fileBeans.add(new FileBean());
        fileBeans.add(new FileBean());
        fileBeans.add(new FileBean());
        rvList.setLayoutManager(new LinearLayoutManager(mContext));
        adapter = new FileAdapter(R.layout.item_file, fileBeans);
        rvList.setAdapter(adapter);
    }

    @Override
    public void initLinsenterner() {
        adapter.setOnItemClickListener(new OnItemClickListener() {
            @Override
            public void onItemClick(@NonNull BaseQuickAdapter<?, ?> adapter, @NonNull View view, int position) {
                startIntent(AppActivityKey.EDITFILEACTIVITY);
            }
        });
    }

    @Override
    public void getData() {

    }

    @OnClick({R2.id.tv_add, R2.id.tv_search})
    public void onViewClicked(View view) {
        int id = view.getId();
        if (id == R.id.tv_add) {
            startIntent(AppActivityKey.ADDFILEACTIVITY);
        } else if (id == R.id.tv_search) {
            startIntent(AppActivityKey.SEARCHFILEACTIVITY);
        }
    }
}